package com.itheima.mapper;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpGender;
import com.itheima.pojo.EmpJob;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {

    @Select("select e.*, d.name deptName from emp e left join dept d on e.dept_id = d.id")
    List<Emp> demoEmpList();

    List<Emp> demoSearch(String name, Integer gender);

    List<Emp> pageList(String name, Integer gender, LocalDate begin, LocalDate end);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, password, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time)" +
            "values (#{username},#{password}, #{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    void deleteByIds(List<Integer> ids);

    Emp selectById(Integer id);

    void updateById(Emp emp);

    @Select("select case job" +
            "           when 1 then '班主任'" +
            "           when 2 then '讲师'" +
            "           when 3 then '学工主管'" +
            "           when 4 then '教研主管'" +
            "           when 5 then '咨询师'" +
            "           else '其它'" +
            "       end job," +
            "       count(*) cnt " +
            "from emp group by job")
    List<EmpJob> empJobData();

    @Select("select case gender " +
            "            when 1 then '男性员工' " +
            "            else '女性员工' " +
            "       end name, " +
            "       count(*) value " +
            "from emp group by gender")
    List<EmpGender> empGenderData();

    @Select("select * from emp")
    List<Emp> selectAll();
    @Select("select * from emp where username=#{username} and password=#{password}")
    Emp login(String username, String password);
}